﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Com.Becom.CommonLibrary.Common
{

    /// <summary>
    /// 基于Log4j的日志记录类。
    /// </summary>
    public class AppLog
    {

        private static readonly log4net.ILog log = log4net.LogManager.GetLogger("LogInfo");
        private static object objLock = new object();

        /// <summary>
        /// 书写日志，普通信息+异常信息
        /// </summary>
        /// <param name="message">提示信息。</param>
        /// <param name="isException">true表示异常日志,false表示操作日志。</param>
        /// <param name="methodBase">方法反射体。</param>
        public static void WriteLog(string message, bool isException, MethodBase methodBase)
        {
            lock (objLock)
            {
                StringBuilder sb = new StringBuilder();
                if (isException)
                {
                    sb.Append("类型：异常|");
                }
                else
                {
                    sb.Append("类型：操作|");
                }
                if (methodBase == null)
                {
                    sb.Append("来源：未知|");
                }
                else
                {
                    sb.Append(string.Format("来源：{0}.{1}|", methodBase.DeclaringType.FullName, methodBase.Name));
                }
                sb.Append("提示：" + message);
                log.Info(sb.ToString());
            }
        }
        public static void Debug(string message)
        {
            lock (objLock)
            {
                log.Debug(message);
            }
        }
    }

}
